module.exports = app => {
  const DataTypes = app.Sequelize
  const sequelize = app.model
  const attributes = {
    id: {
      type: DataTypes.UUID,
      allowNull: false,
      primaryKey: true,
      defaultValue: DataTypes.UUIDV1,
      comment: '主键 唯一标识'
    },
    channelId: {
      type: DataTypes.STRING(32),
      comment: '课程栏目id',
      field: 'channel_id'
    },
    categoryId: {
      type: DataTypes.STRING(32),
      comment: '课程类别id',
      field: 'category_id'
    },
    categoryName: {
      type: DataTypes.STRING(128),
      comment: '课程类别名称',
      field: 'category_name'
    },
    createTime: {
      type: DataTypes.DATE,
      comment: '创建日期',
      field: 'create_time'
    },
    createUser: {
      type: DataTypes.UUID,
      comment: '创建用户',
      field: 'create_user'
    },
    lastTime: {
      type: DataTypes.DATE,
      comment: '修改日期',
      field: 'last_time'
    },
    lastUser: {
      type: DataTypes.UUID,
      comment: '修改用户',
      field: 'last_user'
    },
    deleteFlag: {
      type: DataTypes.BOOLEAN,
      comment: '是否删除（1是，0否）',
      field: 'delete_flag',
      allowNull: false,
      defaultValue: false
    }
  }
  const options = {
    tableName: 'mooc_course_category'
  }
  const CourseCategory = sequelize.define('category', attributes, options)
  CourseCategory.associate = function() {
    app.model.CourseCategory.hasMany(app.model.CourseColumn, { foreignKey: 'channelId' }) // 一个类别属于一个栏目
    app.model.CourseCategory.hasMany(app.model.Course, { foreignKey: 'categoryId' }) // 一个类别属于一个栏目
  }
  return CourseCategory
}
